<template>
  <div class="iheader">
    <div class="btn-wrapper">
      <el-image :src="backPng" @click="goBack" />
      <el-image :src="homePng" @click="goIndex" />
      <!-- <el-button type="default" >返回</el-button> -->
      <!-- <el-button type="default" >首页</el-button> -->
    </div>
    <div class="title">{{ props.title }}</div>
    <div class="btn-group">
      <span class="b-name">{{ userStore.userInfo.username }}</span>
      <div class="b-btn" @click="logoOut">退出登录</div>
    </div>
  </div>
</template>
<script lang="ts" setup>
import { useRouter, useRoute } from "vue-router";
import { useUserStoreHook } from "@/store/modules/user";
import backPng from "@/assets/img/back.png";
import homePng from "@/assets/img/home.png";
const userStore = useUserStoreHook();
const router = useRouter();
const route = useRoute();

const props = defineProps({
  title: {
    type: String,
    required: true
  }
});
function logoOut() {
  userStore.logOut();
}
function goBack() {
  router.back();
  // const matched = route.matched;
  // if (matched[0].path !== "/") {
  //   router.back();
  // } else {
  //   router.push({ path: "/" });
  // }
  // console.log("router:", router);
}
function goIndex() {
  router.push({ path: "/" });
}
</script>
<style lang="scss" scoped>
.iheader {
  width: 100%;
  height: 70px;
  line-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: white;
  padding: 0px 30px;

  .btn-wrapper {
    height: 100%;
    display: flex;
    align-items: center;
    .el-image {
      width: 50px;
      height: 50px;
      margin-right: 24px;
    }
  }
  .title {
    text-align: center;
    font-size: 28px;
    font-weight: bold;
    text-align: center;
    width: 400px;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
  }
  .btn-group {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    .b-name {
      margin-right: 10px;
      font-size: 18px;
      color: #3f4254;
      font-weight: bold;
      width: 120px;
      word-break: keep-all;
      overflow: hidden;
    }
    .b-btn {
      background-color: #3689f5;
      color: white;
      width: 118px;
      height: 50px;
      border-radius: 10px;
      line-height: 50px;
      text-align: center;
    }
  }
}
</style>
